package com.sjb.thread;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 有点儿意思
 * @Description:
 */
public class WaitNotifyDemo {
    public static void main(String[] args) {
        Object lock = new Object();
        ThreadA threadA = new ThreadA(lock);
        ThreadB threadB = new ThreadB(lock);
        threadA.start();
        threadB.start();

    }

    static class ThreadA extends Thread{
        private Object lock;
        public ThreadA(Object lock){
            this.lock = lock;
        }
        @Override
        public void run(){
            synchronized (lock){
                System.out.println("线程A start....");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程A end....");
            }
        }
    }
    static class ThreadB extends Thread{
        private Object lock;

        public ThreadB(Object lock){
            this.lock = lock;
        }
        @Override
        public void run(){
            synchronized (lock){
                System.out.println("线程B start....");
                lock.notify(); // 唤醒线程A
                System.out.println("线程B end....");
            }
        }
    }
}
